IdeaBlade.EntityModel.Compat Assembly > IdeaBlade.EntityModel Namespace > Coroutine Class > Start Method : Start(Func<IEnumerable<INotifyCompleted>>,Action<CoroutineOperation>) Method |
'Declaration
Public Overloads Shared Function Start( _ ByVal coroutine As Func(Of IEnumerable(Of INotifyCompleted)), _ Optional ByVal completedHandler As Action(Of CoroutineOperation) _ ) As CoroutineOperation
'Usage
Dim coroutine As Func(Of IEnumerable(Of INotifyCompleted)) Dim completedHandler As Action(Of CoroutineOperation) Dim value As CoroutineOperation value = Coroutine.Start(coroutine, completedHandler)
public static CoroutineOperation Start( Func<IEnumerable<INotifyCompleted>> coroutine, Action<CoroutineOperation> completedHandler )
See the second example below for how to pass arguments into the iterator.
public void CoroutineSample() { // Note that a new EM is not required for a Coroutine, we show it here for completeness. _mgr = new DomainModelEntityManager(); // Start some serial async operations. var op = Coroutine.Start(SampleActions); // Listen for completion. op.Completed += (s, e) => { if (e.HasError) { MessageBox.Show(e.Error.Message); e.MarkErrorAsHandled(); } }; } private EntityManager _mgr; // A block of asynchronous actions. private IEnumerable<INotifyCompleted> SampleActions() { // Start a query for all customers in specified country, yield when async op completes. var op1 = _mgr.Customers.Where(c => c.Country == "UK").ExecuteAsync(); yield return op1; // Resume execution here when op1 completes. Take a look at results from 1st query TraceFns.WriteLine("Customer count = " + op1.Results.Count().ToString()); // Perform another async quuery for all employees. var op2 = _mgr.Employees.ExecuteAsync(); yield return op2; // Resume execution here when op2 completes. See what it returned. TraceFns.WriteLine("Employee count = " + op2.Results.Count().ToString()); } /***************************************************************************************/ // Sample 2 - passing arguments to an iterator public void CoroutineSample2a() { // Note that a new EM is not required for a Coroutine, we show it here for completeness. _mgr = new DomainModelEntityManager(); // Start some serial async operations. var op = Coroutine.Start(() => SampleActions2("USA")); // Listen for completion. op.Completed += (s, e) => { if (e.HasError) { MessageBox.Show(e.Error.Message); e.MarkErrorAsHandled(); } }; } private IEnumerable<INotifyCompleted> SampleActions2(String country) { // Start a query for all customers in specified country, yield when async op completes. var op1 = _em1.Customers.Where(c => c.Country == country).ExecuteAsync(); yield return op1; // Resume execution here when op1 completes. Take a look at results from 1st query TraceFns.WriteLine("Customer count = " + op1.Results.Count().ToString()); // Perform another async quuery for all employees. var op2 = _em1.Employees.ExecuteAsync(); yield return op2; // Resume execution here when op2 completes. See what it returned. TraceFns.WriteLine("Employee count = " + op2.Results.Count().ToString()); }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2